package com.itheima.case2.web;

import com.itheima.case2.pojo.po.Role;
import com.itheima.case2.pojo.vo.Result;
import com.itheima.case2.service.RoleService;
import com.itheima.case2.utils.BaseController;
import com.itheima.case2.utils.BeansFactory;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@WebServlet("/role/*")
public class RoleServlet extends BaseServlet{
    public void queryAllRoles(HttpServletRequest request, HttpServletResponse response){
        try {
            //使用工厂创建对象
            RoleService roleService = BeansFactory.getInstance("roleServlet");
            //调用对象中的方法
            List<Role> roles = roleService.queryAllRoles();
            //封装结果
            Result result = new Result(true, "查询角色成功",roles);
            //响应给前端
            BaseController.printResult(response,result);
        } catch (Exception e) {
            e.printStackTrace();
            try {
                Result result = new Result(false, "菜");
                //响应给前端
                BaseController.printResult(response,result);
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }


}
